package com.muyu.product.domain;

import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.product.domain.model.TemplateAttributeModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import io.swagger.annotations.*;
import com.muyu.common.core.annotation.Excel;
import com.muyu.product.domain.req.AttributeInfoQueryReq;
import com.muyu.product.domain.req.AttributeInfoSaveReq;
import com.muyu.product.domain.req.AttributeInfoEditReq;
import com.muyu.common.core.web.domain.BaseEntity;

/**
 * 商品属性对象 attribute_info
 *
 * @author DongZeLiang
 * @date 2024-02-27
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("attribute_info")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "AttributeInfo", description = "商品属性")
public class AttributeInfo extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /** 属性编号 */
    @TableId(value = "id",type = IdType.AUTO)
    @ApiModelProperty(name = "属性编号", value = "属性编号")
    private Long id;

    /** 属性编码 */
    @Excel(name = "属性编码")
    @ApiModelProperty(name = "属性编码", value = "属性编码", required = true)
    private String code;

    /** 属性名 */
    @Excel(name = "属性名")
    @ApiModelProperty(name = "属性名", value = "属性名", required = true)
    private String name;


    public TemplateAttributeModel buildTemplateModel(){
        return TemplateAttributeModel.builder()
                .id(this.getId())
                .code(this.getCode())
                .name(this.getName())
                .build();
    }

    /**
    * 查询构造器
    */
    public static AttributeInfo queryBuild( AttributeInfoQueryReq attributeInfoQueryReq){
        return AttributeInfo.builder()
                .name(attributeInfoQueryReq.getName())
                .code(attributeInfoQueryReq.getCode())
                .build();
    }

    /**
    * 添加构造器
    */
    public static AttributeInfo saveBuild(AttributeInfoSaveReq attributeInfoSaveReq){
        return AttributeInfo.builder()
                .name(attributeInfoSaveReq.getName())
                .code(attributeInfoSaveReq.getCode())
                .build();
    }

    /**
    * 修改构造器
    */
    public static AttributeInfo editBuild(Long id, AttributeInfoEditReq attributeInfoEditReq){
        return AttributeInfo.builder()
            .id(id)
                .name(attributeInfoEditReq.getName())
                .code(attributeInfoEditReq.getCode())
                .build();
    }

}
